import com.alibaba.rocketmq.client.producer.DefaultMQProducer;
import com.alibaba.rocketmq.client.producer.SendResult;
import com.taobao.api.internal.tmc.Message;
import com.taobao.api.internal.tmc.MessageHandler;
import com.taobao.api.internal.tmc.MessageStatus;
import com.taobao.api.internal.tmc.TmcClient;

/**
 * Created by pengfei on 16/7/11.
 */
public class tmc {
    public static void main(String[] args) throws Exception {
        final DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");
        producer.setNamesrvAddr("localhost:9876");
        producer.start();

        TmcClient client = new TmcClient("23315789","515603ba71beb9ff7d0e26facc9d5d82", "default");
        client.setMessageHandler(new MessageHandler() {
            public void onMessage(Message message, MessageStatus status) {
                try {
                    System.out.println(message.getContent());
                    if("alibaba_aliqin_FcCallCdr".equals(message.getTopic())){
                        com.alibaba.rocketmq.common.message.Message msg = new com.alibaba.rocketmq.common.message.Message(message.getTopic(),"TagA","OrderID001",message.getContent().getBytes());// body
                        SendResult sendResult = producer.send(msg);
                        System.out.println(sendResult);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    status.fail();
                }
            }
        });
        client.connect("ws://mc.api.taobao.com");

        System.out.println("ok ....");

        System.in.read();
    }
}
